import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/login/Login";
import Home from "@/views/home/Home";
import Welcome from "@/views/home/home_welcome/Welcome";
import User from "@/views/user/User";

import Rights from "@/views/power/rights/Rights";
import Roles from "@/views/power/roles/Roles";
import Cate from "@/views/goods/cate/Cate";
import Params from "@/views/goods/params/Params";


Vue.use(VueRouter)

let routes;
routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    component: Login
  },
  //主页Home
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      {
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/users',
        component: User
      },
      {
        path:'/rights',
        component: Rights
      },
      {
        path: '/roles',
        component:Roles
      },
      {
        path:'/categories',
        component: Cate
      },
      {
        path: '/params',
        component: Params
      }
    ]
  }
];

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.path==='/login') return next();
  const token=window.sessionStorage.getItem("token")
  if (!token) return next('/login')
  next();
})
export default router
